﻿namespace Innovative.ProXr
{
	public enum ConfigurationMode
	{
		Unknown,
		RunMode,
		ConfigurationMode,
		SecurityLockdownMode
	}

	/// <summary>
	/// Converts an API that responds with 0 or 1 to indicate the status
	/// of a relay to an enumeration.
	/// </summary>
	public class ConfigurationModeResponseConverter : IResponseConverter<ConfigurationMode>
	{
		ConfigurationMode IResponseConverter<ConfigurationMode>.Convert(RelayByte[] response)
		{
			ConfigurationMode returnValue = ConfigurationMode.Unknown;

			if (response.Length == 1)
			{
				if (response[0] == 85)
				{
					returnValue = ConfigurationMode.RunMode;
				}
				else if (response[0] == 86)
				{
					returnValue = ConfigurationMode.ConfigurationMode;
				}
				else if (response[0] == 87)
				{
					returnValue = ConfigurationMode.SecurityLockdownMode;
				}
				else
				{
					returnValue = ConfigurationMode.Unknown;
				}
			}
			else
			{
				throw new InvalidResponseException("The ConfigurationModeResponseConverter converter expects a single byte response.");
			}

			return returnValue;
		}
	}
}
